function result = read_gray(filename)

temp = double(imread(filename));

if (size(temp, 3) == 1)
    result = temp;
else
    result = (temp(:,:,1) + temp(:,:,2) + temp(:,:,3))/3;
end
